anim8 = require("lib/anim8")
require("lib/functions")
require("lib/classes")

function love.load()
	map = Map.new(3000, 2000)
	--map = Map.new(300, 300)
	camera = Camera.new()
	player = Player.new(100,100,10,10)
	
	angle = 0
	dangle = 0
	bullets = {}
	animations = {}
end

function love.mousepressed(x, y, button)
	if button == "l" then player:fire() end
end

function love.focus(f) 
	gameIsPaused = not f 
end

function love.update(dt)
	if gameIsPaused then return end
	player:update(dt)
	camera:update(dt)
	
	for i = #bullets, 1, -1 do
		v = bullets[i]
		v:update(dt)
		if not inRange(v.getX(), 0, map.getWidth()) then v:delete(i)
		elseif not inRange(v.getY(), 0, map.getHeight()) then v:delete(i) end
	end
	
	for i = #animations, 1, -1 do
		v = animations[i]
		if v:currentFrame() == v:frameCount() then table.remove(animations, i) end
		v:update(dt)
	end
end

function love.draw()
	love.graphics.setColor(255, 255, 255)
	map:draw()
	player:draw()
	
	for k, v in pairs(bullets) do
		v:draw()
	end
	
	for k, v in pairs(animations) do
		v:draw()
	end
	
	love.graphics.setColor( 0, 0, 0)
	love.graphics.print("FPS: " .. love.timer.getFPS(), 10, 580)
end